library(foreign)
uk_w3<-read.dta("C:/Users/pkb16122/Dropbox/w3_uk.dta", convert.underscore=TRUE)
us_w3<-read.dta("C:/Users/pkb16122/Dropbox/w3_us.dta", convert.underscore=TRUE)
uk_w3<-droplevels(uk_w3)
us_w3<-droplevels(us_w3)


library(car)
library(plyr) 

 
###table of proportions saying too much
ukp1<-prop.table(table(uk_w3$w3faidg1a))
ukp2<-prop.table(table(uk_w3$w3faidg1b))
ukp3<-prop.table(table(uk_w3$w3faidg1c))
ukp4<-prop.table(table(uk_w3$w3faidg1d))
usp1<-prop.table(table(us_w3$w3faidg1a))
usp2<-prop.table(table(us_w3$w3faidg1b))
usp3<-prop.table(table(us_w3$w3faidg1ac))
usp4<-prop.table(table(us_w3$w3faidg1d))




#####tables for experiments

# multiply by 100 and round to 1 decimal place
ukp1<-round(ukp1*100, 1)
ukp2<-round(ukp2*100, 1)
ukp3<-round(ukp3*100, 1)
ukp4<-round(ukp4*100, 1)

usp1<-round(usp1*100, 1)
usp2<-round(usp2*100, 1)
usp3<-round(usp3*100, 1)
usp4<-round(usp4*100, 1)


####  Note:  These are the columns for Table 2 in the Paper
uktable<-matrix(c(ukp1, ukp2, ukp4, ukp3), ncol=4)
rownames(uktable)<-c("Too Little","About Right", "Too much", "Don't Know")
colnames(uktable)<-c("Base Question", "Money", "Percent", "Money and Percent")

######  Note:  These are the columns for Table 1 in the Paper
ustable<-matrix(c(usp1, usp2, usp4, usp3), ncol=4)
rownames(ustable)<-c("Too Little","About Right", "Too much", "Don't Know")
colnames(ustable)<-c("Base Question", "Money", "Percent", "Money and Percent")


### raw numbers for chi square test.
ukp1r<-(table(uk_w3$w3faidg1a))
ukp2r<-(table(uk_w3$w3faidg1b))
ukp3r<-(table(uk_w3$w3faidg1c))
ukp4r<-(table(uk_w3$w3faidg1d))


usp1r<-(table(us_w3$w3faidg1a))
usp2r<-(table(us_w3$w3faidg1b))
usp3r<-(table(us_w3$w3faidg1ac))
usp4r<-(table(us_w3$w3faidg1d))

uktabler<-matrix(c(ukp1r, ukp2r, ukp3r, ukp4r), ncol=4)

ustabler<-matrix(c(usp1r, usp2r, usp3r, usp4r), ncol=4)

# chi square call for the table

# This replicates the chi-square test at the bottom of Table 2 in the Paper
ukchi<-chisq.test(uktabler)

# This replicates the chi-square test at the bottom of Table 1 in the Paper
uschi<-chisq.test(ustabler)

#  Percentages regardless of condition
ukrow<-rowSums(uktabler, na.rm=T)
usrow<-rowSums(ustabler, na.rm=T)

####  Note:  This is the replication of the last cloumn for Table 2 in the Paper
prop.table(ukrow)

##### Note:  This is the replication of the last column for Table 1 in the Paper
prop.table(usrow)


# comparisons for head to head chi square tests

uktable12<-matrix(c(ukp1r, ukp2r), ncol=2)
ustable12<-matrix(c(usp1r, usp2r), ncol=2)
uktable13<-matrix(c(ukp1r, ukp3r), ncol=2)
ustable13<-matrix(c(usp1r, usp3r), ncol=2)
uktable14<-matrix(c(ukp1r, ukp4r), ncol=2)
ustable14<-matrix(c(usp1r, usp4r), ncol=2)
uktable23<-matrix(c(ukp2r, ukp3r), ncol=2)
ustable23<-matrix(c(usp2r, usp3r), ncol=2)
uktable24<-matrix(c(ukp2r, ukp4r), ncol=2)
ustable24<-matrix(c(usp2r, usp4r), ncol=2)
uktable43<-matrix(c(ukp4r, ukp3r), ncol=2)
ustable43<-matrix(c(usp4r, usp3r), ncol=2)

#  Comparisons for head-to-head t-tests
#US
t.base.us<-ifelse(us_w3$w3faidg1a=="Too little", 1, 
                  ifelse(us_w3$w3faidg1a=="About right",2, 
                         ifelse(us_w3$w3faidg1a=="Too much",3,4)))
t.base.us[t.base.us==4]<-NA


t.money.us<-ifelse(us_w3$w3faidg1b=="Too little", 1, 
                  ifelse(us_w3$w3faidg1b=="About right",2, 
                         ifelse(us_w3$w3faidg1b=="Too much",3,4)))
t.money.us[t.money.us==4]<-NA

t.percent.us<-ifelse(us_w3$w3faidg1d=="Too little", 1, 
                   ifelse(us_w3$w3faidg1d=="About right",2, 
                          ifelse(us_w3$w3faidg1d=="Too much",3,4)))
t.percent.us[t.percent.us==4]<-NA

t.money.percent.us<-ifelse(us_w3$w3faidg1ac=="Too little", 1, 
                     ifelse(us_w3$w3faidg1ac=="About right",2, 
                            ifelse(us_w3$w3faidg1ac=="Too much",3,4)))
t.money.percent.us[t.money.percent.us==4]<-NA


#UK
t.base.uk<-ifelse(uk_w3$w3faidg1a=="Too little", 1, 
          ifelse(uk_w3$w3faidg1a=="About right",2, 
                 ifelse(uk_w3$w3faidg1a=="Too much",3,4)))
t.base.uk[t.base.uk==4]<-NA


t.money.uk<-ifelse(uk_w3$w3faidg1b=="Too little", 1, 
                  ifelse(uk_w3$w3faidg1b=="About right",2, 
                         ifelse(uk_w3$w3faidg1b=="Too much",3,4)))
t.money.uk[t.money.uk==4]<-NA

t.percent.uk<-ifelse(uk_w3$w3faidg1d=="Too little", 1, 
                     ifelse(uk_w3$w3faidg1d=="About right",2, 
                            ifelse(uk_w3$w3faidg1d=="Too much",3,4)))

t.percent.uk[t.percent.uk==4]<-NA 


t.money.percent.uk<-ifelse(uk_w3$w3faidg1c=="Too little", 1, 
                     ifelse(uk_w3$w3faidg1c=="About right",2, 
                            ifelse(uk_w3$w3faidg1c=="Too much",3,4)))

t.money.percent.uk[t.money.percent.uk==4]<-NA 

#Here are the US Means for Table 3
mean(t.base.us, na=T)  
mean(t.money.us, na=T)
mean(t.percent.us, na=T) 
mean(t.money.percent.us, na=T)

#Here are the US T-Tests for Table 3
t.test(t.base.us, t.money.us)
t.test(t.base.us, t.percent.us)
t.test(t.base.us, t.money.percent.us)
t.test(t.money.us, t.percent.us)
t.test(t.money.us, t.money.percent.us)
t.test(t.percent.us, t.money.percent.us)

# Here are the UK Means for Table 3
mean(t.base.uk, na=T)
mean(t.money.uk, na=T)
mean(t.percent.uk, na=T)  
mean(t.money.percent.uk, na=T)

# Here are the UK T-Tests for Table 3
t.test(t.base.uk, t.money.uk)
t.test(t.base.uk, t.percent.uk)
t.test(t.base.uk, t.money.percent.uk)
t.test(t.money.uk, t.percent.uk)
t.test(t.money.uk, t.money.percent.uk)
t.test(t.percent.uk, t.money.percent.uk)


library(plyr)

## dependent variable construction
## combine experimental treatments
## dv constructed so 0 is give less--1 means "moving away from wanting to
## give less"

# combining treatments to create dv

uk_w3$ukfaid1<-as.numeric(uk_w3$w3faidg1a)
uk_w3$ukfaid1<-mapvalues(uk_w3$ukfaid1, c(1,2,3,4, NA), c(1,1,0,1, -1))

uk_w3$ukfaid2<-as.numeric(uk_w3$w3faidg1b)
uk_w3$ukfaid2<-mapvalues(uk_w3$ukfaid2, c(1,2,3,4, NA), c(1,1,0,1, -1))

uk_w3$ukfaid3<-as.numeric(uk_w3$w3faidg1c)
uk_w3$ukfaid3<-mapvalues(uk_w3$ukfaid3, c(1,2,3,4, NA), c(1,1,0,1, -1))

uk_w3$ukfaid4<-as.numeric(uk_w3$w3faidg1d)
uk_w3$ukfaid4<-mapvalues(uk_w3$ukfaid4, c(1,2,3,4, NA), c(1,1,0,1, -1))


faiddvukwork<-(uk_w3$ukfaid1+uk_w3$ukfaid2+uk_w3$ukfaid3+uk_w3$ukfaid4)
faiddvukwork<-mapvalues(faiddvukwork, c(-2, -3, -4), c(1,0,NA))
ukdv<-faiddvukwork


us_w3$usfaid1<-as.numeric(us_w3$w3faidg1a)
us_w3$usfaid1<-mapvalues(us_w3$usfaid1, c(1,2,3,4, NA), c(1,1,0,1, -1))

us_w3$usfaid2<-as.numeric(us_w3$w3faidg1b)
us_w3$usfaid2<-mapvalues(us_w3$usfaid2, c(1,2,3,4, NA), c(1,1,0,1, -1))

us_w3$usfaid3<-as.numeric(us_w3$w3faidg1ac)
us_w3$usfaid3<-mapvalues(us_w3$usfaid3, c(1,2,3,4, NA), c(1,1,0,1, -1))

us_w3$usfaid4<-as.numeric(us_w3$w3faidg1d)
us_w3$usfaid4<-mapvalues(us_w3$usfaid4, c(1,2,3,4, NA), c(1,1,0,1, -1))


faiddvuswork<-(us_w3$usfaid1+us_w3$usfaid2+us_w3$usfaid3+us_w3$usfaid4)
faiddvuswork<-mapvalues(faiddvuswork, c(-2, -3, -4), c(1,0,NA))
usdv<-faiddvuswork

##treatment dummies  
library(car)
usbase<-as.numeric(us_w3$w3faidg1a)
usbase<-recode(usbase, "c(1,2,3,4)=1; else=0")
usmoney<-as.numeric(us_w3$w3faidg1b)
usmoney<-recode(usmoney, "c(1,2,3,4)=1; else=0")
usmoneypct<-as.numeric(us_w3$w3faidg1ac)
usmoneypct<-recode(usmoneypct,"c(1,2,3,4)=1; else=0")
uspct<-as.numeric(us_w3$w3faidg1d)
uspct<-recode(uspct,"c(1,2,3,4)=1; else=0")


ukbase<-as.numeric(uk_w3$w3faidg1a)
ukbase<-recode(ukbase, "c(1,2,3,4)=1; else=0")
ukmoney<-as.numeric(uk_w3$w3faidg1b)
ukmoney<-recode(ukmoney, "c(1,2,3,4)=1; else=0")
ukmoneypct<-as.numeric(uk_w3$w3faidg1c)
ukmoneypct<-recode(ukmoneypct,"c(1,2,3,4)=1; else=0")
ukpct<-as.numeric(uk_w3$w3faidg1d)
ukpct<-recode(ukpct,"c(1,2,3,4)=1; else=0")

##  Economics 
##  Personal Household in past year
##  Higher numbers are positive 

###  Note:  usecon1a and ukecon1a replicates table found in Appendix A.1.1
usecon1<-as.numeric(us_w3$w3econ2)
usecon1a<-prop.table(table(as.numeric(us_w3$w3econ2)))
ukecon1<-as.numeric(uk_w3$w3econ2)
ukecon1a<-prop.table(table(as.numeric(uk_w3$w3econ2)))
usecon<-mapvalues(usecon1, c(1,2,3,4,5,6, NA), c(5,4,3,2,1,3,NA))
ukecon<-mapvalues(ukecon1, c(1,2,3,4,5,6, NA), c(5,4,3,2,1,3,NA))




##  Equality
##  1-7--higher scores are government doing more to reduce income inequality
###  Note:  usredist1a and ukredist1a replicates table found in Appendix A.1.2
usredist1<-as.numeric(us_w3$w3EQUALITY1)
usredist1a<-prop.table(table(as.numeric(us_w3$w3EQUALITY1)))
ukredist1<-as.numeric(uk_w3$w3EQUALITY1)
ukredist1a<-prop.table(table(as.numeric(uk_w3$w3EQUALITY1)))
usredist<-mapvalues(usredist1, c(1,2,3,4,5,6,7, NA), c(1,2,3,4,5,6,7, NA))
ukredist<-mapvalues(ukredist1, c(1,2,3,4,5,6,7, NA), c(1,2,3,4,5,6,7, NA))


## Instrumental--British/US aid improves standing
## Higher scores agree
###  Note:  usredist1a and ukredist1a replicates table found in Appendix A.1.3
 


usinst1<-as.numeric(us_w3$w3gates1)

ukinst1<-as.numeric(uk_w3$w3gates1)
usinst<-mapvalues(usinst1, c(1,2,3,4,5,6, NA), c(5,4,3,2,1,3,NA))
ukinst<-mapvalues(ukinst1, c(1,2,3,4,5,6, NA), c(5,4,3,2,1,3,NA))
usinst1a<-prop.table(table(as.numeric(usinst)))
ukinst1a<-prop.table(table(as.numeric(ukinst)))

## Aid prevents terrorism
## Higher scores agree
usinst2<-as.numeric(us_w3$w3gates2)
ukinst2<-as.numeric(uk_w3$w3gates2)
usaidprterr<-mapvalues(usinst2, c(1,2,3,4,5,6, NA), c(5,4,3,2,1,3,NA))
ukaidprterr<-mapvalues(ukinst2, c(1,2,3,4,5,6, NA), c(5,4,3,2,1,3,NA))
usinst2a<-prop.table(table(as.numeric(usaidprterr)))
ukinst2a<-prop.table(table(as.numeric(ukaidprterr)))


##  Ideology--higher scores more right
usideo1<-as.numeric(us_w3$w3wing1a)
ukideo1<-as.numeric(uk_w3$w3wing1a)
usideo<-mapvalues(usideo1, c(1,2,3,4,5,6,7,8,9,10,997, NA), c(1,2,3,4,5,6,7,8,9,10,5,NA))
ukideo<-mapvalues(ukideo1, c(1,2,3,4,5,6,7,8,9,10,997, NA), c(1,2,3,4,5,6,7,8,9,10,5,NA))
## This replicates information contained in Appendix A.1.4
mean(ukideo, na=T)
median(ukideo, na=T)
mean(usideo, na=T)
median(ukideo, na=T)
##  us partisanship
democrat1<-as.numeric(us_w3$w3USparty1)
democrat2<-as.numeric(us_w3$w3USparty2)
democrata<-mapvalues(democrat1, c(1,2,3,4,5,6,NA), c(0,1,0,0,0,0,0))
democratb<-mapvalues(democrat2, c(1,2,3,4,5,6,NA), c(1,0,0,0,0,0,0))
democrat<-democrata+democratb
republican1<-as.numeric(us_w3$w3USparty1)
republican2<-as.numeric(us_w3$w3USparty2)
republicana<-mapvalues(republican1, c(1,2,3,4,5,6,NA), c(1,0,0,0,0,0,0))
republicanb<-mapvalues(republican2, c(1,2,3,4,5,6,NA), c(0,1,0,0,0,0,0))
republican<-republicana+republicanb

### ## This replicates information contained in Appendix A.1.4
prop.table(table(republican))
prop.table(table(democrat))  

## UK Partisanship 
labour1<-as.numeric(uk_w3$w3UKparty1)
labour2<-as.numeric(uk_w3$w3UKparty2)
labour3<-as.numeric(uk_w3$w3UKparty3)
laboura<-mapvalues(labour1, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,1,0,0,0,0,0,0,0,0,0,0))
labourb<-mapvalues(labour2, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(1,0,0,0,0,0,0,0,0,0,0,0))
labourc<-mapvalues(labour3, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,1,0,0,0,0,0,0,0,0,0))
labour<-laboura+labourb+labourc




cons1<-as.numeric(uk_w3$w3UKparty1)
cons2<-as.numeric(uk_w3$w3UKparty2)
cons3<-as.numeric(uk_w3$w3UKparty3)
consa<-mapvalues(cons1, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(1,0,0,0,0,0,0,0,0,0,0,0))
consb<-mapvalues(cons2, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,1,0,0,0,0,0,0,0,0,0))
consc<-mapvalues(cons3, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,1,0,0,0,0,0,0,0,0,0,0))
cons<-consa+consb+consc


lib1<-as.numeric(uk_w3$w3UKparty1)
lib2<-as.numeric(uk_w3$w3UKparty2)
lib3<-as.numeric(uk_w3$w3UKparty3)

liba<-mapvalues(lib1, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,1,0,0,0,0,0,0,0,0,0))
libb<-mapvalues(lib2, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,1,0,0,0,0,0,0,0,0,0,0))
libc<-mapvalues(lib3, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(1,0,0,0,0,0,0,0,0,0,0,0))
libdem<-liba+libb+libc





nat1<-as.numeric(uk_w3$w3UKparty1)
nat2<-as.numeric(uk_w3$w3UKparty2)
nat3<-as.numeric(uk_w3$w3UKparty3)
nata<-mapvalues(nat1, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,0,1,1,0,0,0,0,0,0,0))
natb<-mapvalues(nat2, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,0,1,1,0,0,0,0,0,0,0))
natc<-mapvalues(nat3, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,0,1,1,0,0,0,0,0,0,0))
nationalist<-nata+natb+natc




ukip1<-as.numeric(uk_w3$w3UKparty1)
ukip2<-as.numeric(uk_w3$w3UKparty2)
ukip3<-as.numeric(uk_w3$w3UKparty3)

ukipa<-mapvalues(ukip1, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,0,0,0,0,1,0,0,0,0,0))
ukipb<-mapvalues(ukip2, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,0,0,0,0,1,0,0,0,0,0))
ukipc<-mapvalues(ukip3, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,0,0,0,0,1,0,0,0,0,0))
ukip<-ukipa+ukipb+ukipc




green1<-as.numeric(uk_w3$w3UKparty1)
green2<-as.numeric(uk_w3$w3UKparty2)
green3<-as.numeric(uk_w3$w3UKparty3)
greena<-mapvalues(green1, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,0,0,0,1,0,0,0,0,0,0))
greenb<-mapvalues(green2, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,0,0,0,1,0,0,0,0,0,0))
greenc<-mapvalues(green3, c(1,2,3,4,5,6,7,8,9,10,11,NA), 
	c(0,0,0,0,0,1,0,0,0,0,0,0))
green<-greena+greenb+greenc


### ## This replicates information contained in Appendix A.1.4
prop.table(table(green))
prop.table(table(ukip))
prop.table(table(nationalist))
prop.table(table(libdem))
prop.table(table(cons))
prop.table(table(labour))

#  demogrpahics us
ageus<-(2013-us_w3$birthyr)
femaleus<-as.numeric(us_w3$gender)
femaleus<-mapvalues(femaleus, c(1,2,NA), c(0,1,NA))
religionus<-as.numeric(us_w3$religpew)
religionus<-mapvalues(religionus, c(1,2,3,4,5,6,7,8,9,10,11,12, NA),
	c(1,1,1,1,1,1,1,1,0,0,0,1,NA))

### ## This replicates information contained in Appendix A.1.5
 


prop.table(table(religionus))
prop.table(table(femaleus)) 
mean(ageus, na=T)
median(ageus, na=T)

# demographics uk
ageuk<-(uk_w3$Age)
femaleuk<-as.numeric(uk_w3$w3sex1)
femaleuk<-mapvalues(femaleuk, c(1,2,NA), c(0,1,NA))
religionuk<-as.numeric(uk_w3$Religion.stat)
religionuk<-mapvalues(religionuk, c(1,2,3,4,NA), c(1,0,0,0,0))

prop.table(table(religionuk))
prop.table(table(femaleuk))  
mean(ageuk, na=T)
median(ageuk, na=T)



###  Alpha coefficients for instrumentalism variables
### ## This replicates information contained in Appendix A.1.3
 
library(psych)

usainst<-data.frame(usinst, usaidprterr)
alpha(usainst, na=T)
uscombinst<-usinst+usaidprterr
median(uscombinst, na.rm=TRUE)

### usinstrumentalist dummy
 
usinsdum<-ifelse(uscombinst<=6, 0, 1)

###  UK combined instrumentalist
ukinsta<-data.frame(ukinst, ukaidprterr)
alpha(ukinsta, na=T)
ukcombinst<-ukinst+ukaidprterr
median(ukcombinst, na.rm=TRUE)

##uk instrumentalist dummy
ukinsdum<-ifelse(ukcombinst<=6, 0, 1)







## dummying economics
# Redistribution Dummies 

usredistdum<-ifelse(usredist<=4,0,1)
ukredistdum<-ifelse(ukredist<=4,0,1)
usecondum<-ifelse(usecon<=3,0,1)
ukecondum<-ifelse(ukecon<=3,0,1)


#####  This is probit without interactions

### This replicates Appendix 2 Table A1, Column US A
usprobitinstredd<-glm(usdv~usmoney+ usmoneypct+uspct+usecondum+usredistdum+usinsdum+usideo+democrat+republican+ageus+femaleus+religionus
, family=binomial(link="probit"))

us.e<-usprobitinstredd

### This replicates Appendix 2 Table A1, Column UK A
ukprobitinstredd<-glm(ukdv~ukmoney+ ukmoneypct+ukpct+ukecondum+ukredistdum+ukinsdum+ ukideo+labour+cons+libdem+nationalist+ukip+green+
ageuk+femaleuk+religionuk
, family=binomial(link="probit"))


uk.e<-ukprobitinstredd




##  Interactions
##  Redistribution
ukmoneyredist<-ukmoney*ukredistdum
ukmoneypctredist<-ukmoneypct*ukredistdum
ukpctredist<-ukpct*ukredistdum

usmoneyredist<-usmoney*usredistdum
usmoneypctredist<-usmoneypct*usredistdum
uspctredist<-uspct*usredistdum


#  Instrumentalism

ukmoneyinstru<-ukmoney*ukinsdum
ukmoneypctinstru<-ukmoneypct*ukinsdum
ukpctinstru<-ukpct*ukinsdum

usmoneyinstru<-usmoney*usinsdum
usmoneypctinstru<-usmoneypct*usinsdum
uspctinstru<-uspct*usinsdum


#  Economic Well Being dummies

ukmoneyecon<-ukmoney*ukecondum
ukmoneypctecon<-ukmoneypct*ukecondum
ukpctecon<-ukpct*ukecondum

usmoneyecon<-usmoney*usecondum
usmoneypctecon<-usmoneypct*usecondum
uspctecon<-uspct*usecondum





##  probits with all interactions

### ### This replicates Appendix 2 Table A1, Column US B
usprobitallinteract<-glm(usdv~usmoney+ usmoneypct+uspct+usecondum+usredistdum+usinsdum+usideo+democrat+republican+ageus+femaleus+religionus+
usmoneyecon+ usmoneypctecon+ uspctecon +
usmoneyinstru + usmoneypctinstru + uspctinstru +
usmoneyredist + usmoneypctredist + uspctredist
, family=binomial(link="probit"))


us.i<-usprobitallinteract

### This replicates Appendix 2 Table A1, Column US B
ukprobitallinteract<-glm(ukdv~ukmoney+ ukmoneypct+ukpct+ukecondum+ukredistdum+ukinsdum+ ukideo+labour+cons+libdem+nationalist+ukip+green+
ageuk+femaleuk+religionuk+
ukmoneyecon + ukmoneypctecon + ukpctecon +
 ukpctinstru+ukmoneyinstru + ukmoneypctinstru +
ukmoneyredist + ukmoneypctredist + ukpctredist, family=binomial(link="probit"), na.action=na.exclude)


uk.i<-ukprobitallinteract



###  Marginal effects

ukmarginaldf<-data.frame(ukdv,ukmoney,ukmoneypct,ukpct,ukecondum,ukredistdum,ukinsdum,ukideo,labour,cons,libdem,nationalist,ukip,green,
ageuk,femaleuk,religionuk,
ukmoneyecon, ukmoneypctecon,ukpctecon,
 ukpctinstru, ukmoneyinstru, ukmoneypctinstru,
ukmoneyredist, ukmoneypctredist, ukpctredist)



usmarginaldf<-data.frame(usdv,usmoney,usmoneypct,uspct,usecondum,usredistdum,usinsdum,usideo, democrat, republican,
ageus,femaleus,religionus,
usmoneyecon, usmoneypctecon,uspctecon,
 uspctinstru, usmoneyinstru, usmoneypctinstru,
usmoneyredist, usmoneypctredist, uspctredist)




library(mfx)

### This replicates Table 4, Column "US Model B"
ukmarginals<-probitmfx(formula=ukdv~ukmoney+ukmoneypct+ukpct+ukecondum+ukredistdum+ukinsdum+ukideo+labour+cons+libdem+nationalist+ukip+green+
ageuk+femaleuk+religionuk+
ukmoneyecon+ ukmoneypctecon+ukpctecon+
 ukpctinstru+ ukmoneyinstru+ ukmoneypctinstru+
ukmoneyredist+ ukmoneypctredist+ ukpctredist, data=ukmarginaldf)


### This replicates Table 4, Column "US Model B"
usmarginals<-probitmfx(formula=usdv~usmoney+usmoneypct+uspct+usecondum+usredistdum+usinsdum+usideo+ democrat+republican+
ageus+femaleus+religionus+
usmoneyecon+ usmoneypctecon+uspctecon+
 uspctinstru+ usmoneyinstru+ usmoneypctinstru+
usmoneyredist+ usmoneypctredist+ uspctredist, data=usmarginaldf)


### This replicates Table 4, Column "US Model A"
usmarginalsnoint<-probitmfx(formula=usdv~usmoney+usmoneypct+uspct+usecondum+usredistdum+usinsdum+usideo+ democrat+republican+
ageus+femaleus+religionus, data=usmarginaldf)

####  This replicates Table 4, Colum "UK Model A"
ukmarginalsnoint<-probitmfx(formula=ukdv~ukmoney+ukmoneypct+ukpct+ukecondum+ukredistdum+ukinsdum+ukideo+labour+cons+libdem+nationalist+ukip+green+
ageuk+femaleuk+religionuk, data=ukmarginaldf)




#  These commands Make it Easier to Construct Tables Found in Appendix 1
# Personal Economic Retrospetions
useconny<-as.matrix(prop.table(table(ukecon1))*100)
round(useconny,1)

ukeconny<-as.matrix(prop.table(table(ukecon1))*100)
round(ukeconny,1)

#  Redistribution

usredistty<-as.matrix(prop.table(table(usredist1))*100)
round(usredistty,1)

ukredistty<-as.matrix(prop.table(table(ukredist1))*100)
round(ukredistty,1)

#  Instrumentalism

usinsty<-as.matrix(prop.table(table(usinst))*100)
round(usinsty,1)


ukinsty<-as.matrix(prop.table(table(ukinst))*100)
round(ukinsty,1)


usaidprterry<-as.matrix(prop.table(table(usaidprterr))*100)
round(usaidprterry,1)


ukaidprterry<-as.matrix(prop.table(table(ukaidprterr))*100)
round(ukaidprterry,1)


#  mfx, no instrumentalism

### This Replicates Appendix A3, Table A2, Column "US A"
 
usmarginalsnoinst<-probitmfx(formula=usdv~usmoney+usmoneypct+uspct+usecondum+usredistdum+usideo+ democrat+republican+
ageus+femaleus+religionus, data=usmarginaldf)


### This Replicates Appendix A3, Table A2, Column "US B"

usmarginalsnoninstint<-probitmfx(formula=usdv~usmoney+usmoneypct+uspct+usecondum+usredistdum+usideo+ democrat+republican+
ageus+femaleus+religionus+
usmoneyecon+ usmoneypctecon+uspctecon+
usmoneyredist+ usmoneypctredist+ uspctredist, data=usmarginaldf)

#### Note, this replicates Appendix A3, Table A2, Column "UK A"
  
ukmarginalsnoinst<-probitmfx(formula=ukdv~ukmoney+ukmoneypct+ukpct+ukecondum+ukredistdum+ukideo+labour+cons+libdem+
nationalist+ukip+green+ageuk+femaleuk+religionuk, data=ukmarginaldf)

#### Note, this replicates Appendix A3, Table A2, Column "UK B"
ukmarginalsint<-probitmfx(formula=ukdv~ukmoney+ukmoneypct+ukpct+ukecondum+ukredistdum+ukideo+labour+cons+libdem+nationalist+ukip+green+
ageuk+femaleuk+religionuk+
ukmoneyecon+ ukmoneypctecon+ukpctecon+ukmoneyredist+ ukmoneypctredist+ ukpctredist, data=ukmarginaldf)


# probit results--
summary(us.e)
summary(us.i)
summary(us.e)
summary(uk.i)


#  Wald tests for probits

#  These are the chi-square statistics found in Table A1 of Appendix A.2
library(aod)
wald.test(b = coef(us.e), Sigma = vcov(us.e), Terms = 1:13)
wald.test(b = coef(us.i), Sigma = vcov(us.i), Terms = 1:22)
wald.test(b = coef(uk.e), Sigma = vcov(uk.e), Terms = 1:16)
wald.test(b = coef(uk.i), Sigma = vcov(uk.i), Terms = 1:25)


#  These are the pseudo r-square statistics found in Table A1 of Appendix A.2

library(pscl)
pR2(us.e)
pR2(us.i)
pR2(uk.e)
pR2(uk.i)

 